package com.csoa.community.services;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.csoa.community.R;
import com.csoa.community.activity.AlermActivity;
import com.csoa.community.bean.RiChengModel;
import com.csoa.community.requests.RiChengRequest;

public class AlarmReceiver extends BroadcastReceiver {
	int i = 0;
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.e("", "AlarmReceiver：" + i);
		i ++;
		if (intent.getAction().equals(RiChengRequest.action)) {
			RiChengModel model = (RiChengModel) intent.getSerializableExtra(RiChengRequest.extra_model);
			Intent in = new Intent(context, AlermActivity.class);
			in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			in.putExtra(RiChengRequest.extra_model, model);
			NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
			Notification notification = new Notification(R.drawable.icon, "会议提醒", System.currentTimeMillis()); 
			notification.setLatestEventInfo(context, 
					model.name, 
					model.time_start + "-" + model.time_end,
					PendingIntent.getActivity( 
							context, 0, 
							in, 0));
			notification.flags|=Notification.FLAG_AUTO_CANCEL; 
			notification.defaults |= Notification.DEFAULT_SOUND; 
			manager.notify((int)System.currentTimeMillis(), notification); 
		}
	}
}
